package com.shouhuobao.take.parcel;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shouhuobao.station.R;
import com.shouhuobao.take.model.ContactPeopleBean;
import com.shouhuobao.take.utils.StringUtils;

import java.util.ArrayList;

import droid.frame.activity.base.BaseAdapterExt;

/**
 * Created by joker on 2017/7/14.
 */

public class ParcelSelectReceiverAdapter extends BaseAdapterExt<ContactPeopleBean> {
    private ViewHolder viewHolder;

    public ParcelSelectReceiverAdapter(ArrayList<ContactPeopleBean> items, Activity context) {
        super(items, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (hasEmptyView()) {
            return super.getView(position, convertView, parent);
        }
        viewHolder = new ViewHolder();
        ContactPeopleBean item = items.get(position);
        if (item.getItem_type() == ContactPeopleBean.TYPE_CHARACTER) {
            convertView = LayoutInflater.from(context).inflate(R.layout.take_companycompany_item, parent, false);
            viewHolder.indexTv = (TextView) convertView.findViewById(R.id.indexTv);
            viewHolder.indexTv.setText(item.getName());
        } else {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_parcel_receiver, parent, false);
            viewHolder.nameTV = (TextView) convertView.findViewById(R.id.name_TV);
            viewHolder.phoneTV = (TextView) convertView.findViewById(R.id.phone_TV);
            if ("#".equals(item.getName())) {
                viewHolder.nameTV.setText("");
            } else {
                viewHolder.nameTV.setText(item.getName());
            }
            viewHolder.phoneTV.setText(StringUtils.splitNumString(1, item.getPhone()));
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView indexTv;
        private TextView nameTV;
        private TextView phoneTV;
    }
}

